package com.wpen.unit.service.job.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wpen.unit.cvt.job.JobUndoPlanCvt;
import com.wpen.unit.infra.mybatis.job.po.JobUndoPlanPo;
import com.wpen.unit.infra.repository.job.JobUndoPlanRepository;
import com.wpen.unit.service.job.JobUndoPlanService;
import com.wpen.unit.web.dto.job.JobUndoPlanListRequest;
import com.wpen.unit.web.dto.job.JobUndoPlanListResponse;
import com.wpen.unit.web.dto.job.JobUndoPlanListRowsResponse;

/**
 * 任务作业未执行业务处理.
 * 
 * @author Wang Peng
 * @date 2022-12-11
 */
@Service
public class JobUndoPlanServiceImpl implements JobUndoPlanService {

    @Autowired
    private JobUndoPlanRepository jobUndoPlanRepository;

    @Override
    public JobUndoPlanListResponse queryListJobUndoPlan(JobUndoPlanListRequest jobUndoPlanListRequest){
        int index = jobUndoPlanListRequest.getIndex();
    	int size = jobUndoPlanListRequest.getSize();
        // 数据库查询
        JobUndoPlanPo jobUndoPlanPo = JobUndoPlanCvt.INSTANCE.queryListDto2Do(jobUndoPlanListRequest);

        long total = jobUndoPlanRepository.count(jobUndoPlanPo);
        List<JobUndoPlanPo> jobUndoPlanPoLists = jobUndoPlanRepository.queryList(index, size,jobUndoPlanPo);

        // 返回响应信息
        JobUndoPlanListResponse jobUndoPlanListResponse = new JobUndoPlanListResponse();
        jobUndoPlanListResponse.setTotal(total);
		jobUndoPlanListResponse.setCount(0);
        if (jobUndoPlanPoLists != null) {
            jobUndoPlanListResponse.setCount(jobUndoPlanPoLists.size());
            List<JobUndoPlanListRowsResponse> listRows = jobUndoPlanListResponse.getRows();
            for (JobUndoPlanPo inJobUndoPlanPo : jobUndoPlanPoLists) {
                JobUndoPlanListRowsResponse row = JobUndoPlanCvt.INSTANCE.queryListRowDo2Dto(inJobUndoPlanPo);
                // row.setId(inJobUndoPlanPo.getId());
                // row.setAppMode(inJobUndoPlanPo.getAppMode());
                // row.setAzCode(inJobUndoPlanPo.getAzCode());
                // row.setAppJarName(inJobUndoPlanPo.getAppJarName());
                // row.setJobTriggerTime(inJobUndoPlanPo.getJobTriggerTime());
                // row.setExecStatus(inJobUndoPlanPo.getExecStatus());
                listRows.add(row);
            }
            jobUndoPlanListResponse.setRows(listRows);
        }

        return jobUndoPlanListResponse;
    }

}
